﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;

namespace Ewts.ashx
{
    /// <summary>
    /// BasicStorage 的摘要说明
    /// </summary>
    public class BasicStorage : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.ContentEncoding = System.Text.Encoding.UTF8;
            StringBuilder items = new StringBuilder();
            DataTable dt = new DataTable();

            //根据当前登录者获取相应库位的处理地
            //2013.05.24  Anling
            string where = "";
            //if (context.Request["belong"] != null && context.Request["belong"].ToString().Trim() != "")
            //{
            //    where = "belongCity='" + context.Request["belong"].ToString().Trim() + "'";
            //}
           

            if (context.Request["graphic"] != null && context.Request["graphic"].ToString().Trim() != "")
            {
                if (where != "")
                {
                    where += " and ";
                }
                where += "graphicCity='" + HttpUtility.UrlDecode(context.Request["graphic"].ToString().Trim()) + "'";
            }
            //if (context.Request["belong"] != null && context.Request["belong"].ToString().Trim() != "")
            //{
            //    if (where != "")
            //    {
            //        where += " and ";
            //    }
            //    where += "belongCity='" + HttpUtility.UrlDecode(context.Request["belong"].ToString().Trim()) + "'";

            //}
            if (context.Request["word"] != null && context.Request["word"].ToString().Trim() != "")
            {
                if (where != "")
                {
                    where += " and ";
                }
                where += "storagecode like '%" + HttpUtility.UrlDecode(context.Request["word"].ToString().Trim()) + "%'";
            }
           dt = new DataLib.BLL.StoragePostion().GetList(10,where,"id").Tables[0];
      
            //for (int i = 0; i < dt.Rows.Count; i++)
            //{

            //    items.Append(dt.Rows[i]["storagecode"].ToString());
            //    items.Append("@");
            //    items.Append(dt.Rows[i]["id"].ToString());

            //    items.Append("\n");
            //}

            items.Append("[");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                items.Append("{\"label\":\"");
                items.Append(dt.Rows[i]["storagecode"].ToString());
                items.Append("\",\"value\":\"");
                items.Append(dt.Rows[i]["id"].ToString());
                items.Append("\"},");
            }
            items.Remove(items.Length - 1, 1);
            items.Append("]");
            context.Response.Write(items);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}